var app = angular.module("app",[]);
app.factory('HttpService', ["$http","$q", "$rootScope", "$window",function ($http,$q, $rootScope, $window) {
  var service = {};
	var urlroot = "http://119.29.159.163:8080/baihua";
  service.ajaxData = function (meaths, apiUrl, data) {
    var deferred = $q.defer();
    var url = urlroot + apiUrl;
    $.ajax({  
        type: meaths,  
        url: url, 
        data: data,
        success:function(data){
          deferred.resolve(data);
      },
      error:function(error){
        deferred.reject(error);
      }
    });
    return deferred.promise;
  }
  service.mylocalStorage = (function(){
    return {
      set: function(key, value) {
       $window.localStorage[key] = value;
        return "save successfully";
      },
      get: function(key) {
        return $window.localStorage[key] || undefined;
      },
      setObject: function(key, value) {
        $window.localStorage[key] = JSON.stringify(value);
        return "save successfully";
      },
      getObject: function(key) {
        return JSON.parse($window.localStorage[key] || '{}');
      },
      remove: function(key) {
        $window.localStorage.removeItem(key);
        return "remove successfully";
      }
    }
  }())
  return service;
}])
